﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataLayer;

/// <summary>
/// Summary description for BusinessClass
/// </summary>
public class BusinessClass
{
	public BusinessClass()
	{
		
    }

    public void insertStudentData(string FullName, string DOB, string certificate)
    {

        int studentid=0;
        DataClassesDataContext ob = new DataClassesDataContext();
       int flag=ob.InsertStudentBasicInfo(FullName, Convert.ToDateTime(DOB));
        if(flag==0)
        {
          var result = ob.GetMaxStudentId().ToList<GetMaxStudentIdResult>();
        
          if (result.Count > 0)
          {
              studentid = Convert.ToInt32(result[0].id);
          }


            
           List<string>  certificate_split=certificate.Split('^').ToList<string>();
            for (var i = 0; i < certificate_split.Count-1; i++)
            {
                List<string> values = certificate_split[i].Split('*').ToList<string>();
                ob.InsertStudentSertificate(studentid, values[0].ToString(), Convert.ToDateTime(values[1]));
            }

        }
    }

    public List<ShowStudentInfoResult> showStudentInfo()
    {
        DataClassesDataContext ob = new DataClassesDataContext();
        return ob.ShowStudentInfo().ToList<ShowStudentInfoResult>();
    }

    public void deleteCertificate(int student_pk,int student_fk)
    {
        DataClassesDataContext ob = new DataClassesDataContext();
        ob.DeleteCertificate(student_pk, student_fk);
    }


}